package com.stgy.lease.web.admin.controller.room;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stgy.lease.common.result.Result;
import com.stgy.lease.model.domain.RoomInfo;
import com.stgy.lease.web.admin.dto.RoomInfoSearchDto;
import com.stgy.lease.web.admin.dto.RoomInfoSubmitDto;
import com.stgy.lease.web.admin.service.RoomInfoService;
import com.stgy.lease.web.admin.vo.RoomDetailVo;
import com.stgy.lease.web.admin.vo.RoomItemVo;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * ClassName:RoomController
 * Package:com.stgy.lease.web.admin.controller.room
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/2 - 8:44
 */
@RestController
@RequestMapping("/admin/room")
@Tag(name = "房间管理模块")
public class RoomController {

    @Autowired
    private RoomInfoService roomInfoService;

    //http://localhost:5174/admin/room/saveOrUpdate POST
    @Operation(summary = "新增或更新房间信息")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody RoomInfoSubmitDto roomInfoSubmitDto) throws Exception {
        return Result.build(roomInfoService.saveOrUpdateRoomInfoSubmitDto(roomInfoSubmitDto));
    }

    //http://localhost:5174/admin/room/pageItem?
    // current=1&size=10&provinceId=44&cityId=4403&districtId=440306&
    // apartmentId=1830404678916026369
    @Operation(summary = "条件查询房间分页列表")
    @GetMapping("/pageItem")
    public Result<Page<RoomItemVo>> pageItem(RoomInfoSearchDto roomInfoSearchDto) {
        return Result.ok(roomInfoService.pageItem(roomInfoSearchDto));
    }

    //http://localhost:5174/admin/room/removeById?id=2 DELETE
    @Operation(summary = "根据id删除房间")
    @DeleteMapping("/removeById")
    public Result<String> removeById(@RequestParam Long id) {
        return Result.build(roomInfoService.removeRoomInfoById(id));
    }

    //    http://localhost:5174/admin/room/updateReleaseStatusById?id=1830435206989889537&status=1 POST
    @Operation(summary = "根据id修改房间状态")
    @PostMapping("/updateReleaseStatusById")
    public Result<String> updateReleaseStatusById(@RequestParam Long id,
                                                  @RequestParam Integer status) {
        return Result.build(roomInfoService.updateReleaseStatusById(id, status));
    }

    //    http://localhost:5174/admin/room/getDetailById?id=1830435206989889537 GET
    @Operation(summary = "根据id获取房间详细信息")
    @GetMapping("/getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam Long id) {
        return Result.ok(roomInfoService.getDetailById(id));
    }

    //http://localhost:5174/admin/room/listBasicByApartmentId?id=1830404678916026369 GET
    @Operation(summary = "根据公寓id查询房间列表")
    @GetMapping("/listBasicByApartmentId")
    public Result<List<RoomInfo>> listBasicByApartmentId(@RequestParam Long id) {
        return Result.ok(roomInfoService.listBasicByApartmentId(id));
    }
}